package com.dz.Incubator.service.impl;

import com.dz.Incubator.dao.BillDao;
import com.dz.Incubator.entity.BillEntity;
import com.dz.Incubator.service.BillService;
import com.dz.Incubator.config.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class BillServiceImpl implements BillService {

	private static final Logger logger = LoggerFactory.getLogger(BillService.class);

    @Autowired
    private BillDao billDao;

    @Override
    public BillEntity insert(BillEntity billEntity) {
        billEntity.setCreateTime(new Date());
        billEntity.setUpdateTime(new Date());
        billDao.insert(billEntity);
        
        return billEntity;
    }

    @Override
    public BillEntity update(BillEntity billEntity) {
        billDao.update(billEntity);
        
        return billEntity;
    }

    @Override
    public Integer delete(Long id) {
        int ret = billDao.delete(id);
        return ret;
    }
    
    @Override
    public List<BillEntity> find(Long[] ids) {
        List<BillEntity> datas = billDao.find(ids);
        return datas;
    }

    @Override
    public BillEntity get(Long id) {
        BillEntity billEntity = billDao.get(id);
        return billEntity;
    }

    @Override
    public List<BillEntity> findAll() {
    	List<BillEntity> datas = billDao.findAll();
    	return datas;
    }
    
    @Override
    public Pagination  findByPagination(Pagination pagination) {
    	List<BillEntity> datas = billDao.findByPagination(pagination);
    	pagination.setList(datas);
    	return pagination;
    }
	
	@Override
    public List<BillEntity> insertBatch(List<BillEntity> list) {
        int ret = billDao.insertBatch(list);
        return list;
    }
    
    @Override
    public List<BillEntity> updateBatch(List<BillEntity> list) {
        int ret = billDao.updateBatch(list);
        return list;
    }
    
    @Override
    public List<Long> deleteBatch(Long[] ids) {
        int ret = billDao.deleteBatch(ids);
        List<BillEntity>  datas = billDao.find(ids);
        List<Long> list = new ArrayList<Long>();
        for (BillEntity data : datas) {
        	list.add(data.getId());
        }
        return list;
    }

    @Override
    public List<BillEntity> findByUserId(int userId) {
        return this.billDao.findByUserId(userId);
    }
}